import { createBrowserRouter, Navigate } from 'react-router-dom'
import { lazy } from 'react'

// 默认导入路由方式
// import Discover from '@/views/discover'
// import Mine from '@/views/mine'
// import Focus from '@/views/focus'
// import Download from '@/views/download'
// import Layout from '@/views/layout'

// 懒加载方式导入路由组件
const Discover = lazy(() => import('@/views/discover'))
const Recommend = lazy(() => import('@/views/discover/recommend'))
const Album = lazy(() => import('@/views/discover/album'))
const Artist = lazy(() => import('@/views/discover/artist'))
const Djradio = lazy(() => import('@/views/discover/djradio'))
const Ranking = lazy(() => import('@/views/discover/ranking'))
const Songs = lazy(() => import('@/views/discover/songs'))

const Mine = lazy(() => import('@/views/mine'))
const Focus = lazy(() => import('@/views/focus'))
const Download = lazy(() => import('@/views/download'))
const Layout = lazy(() => import('@/views/layout'))

const router = createBrowserRouter([
  {
    path: '/',
    element: <Layout />,
    children: [
      {
        index: true, // 默认显示的一级路由
        // element: <Discover />
        element: <Navigate to={'/discover'} />
      },
      {
        path: '/discover',
        element: <Discover />,
        children: [
          {
            index: true, // 默认显示的二级路由
            element: <Recommend />
          },
          {
            path: '/discover/recommend',
            element: <Recommend />
          },
          {
            path: '/discover/album',
            element: <Album />
          },
          {
            path: '/discover/artist',
            element: <Artist />
          },
          {
            path: '/discover/djradio',
            element: <Djradio />
          },
          {
            path: '/discover/ranking',
            element: <Ranking />
          },
          {
            path: '/discover/songs',
            element: <Songs />
          }
        ]
      },
      {
        path: '/mine',
        element: <Mine />
      },
      {
        path: '/focus',
        element: <Focus />
      },
      {
        path: '/download',
        element: <Download />
      }
    ]
  }
])

export default router
